import { OtherFeeType } from "./otherFeeType"
import { CsFundDouble } from "../common/csFundDouble.js";
import { Util } from "../../utils/util.js";

export class OtherFundDouble {
    _otherFeeType = null;   // OtherFeeType
    _fundDouble = CsFundDouble.zero();


    // type OtherFeeType
    // fundDouble : CsFundDouble
    constructor(type, fundDouble) {
        this._otherFeeType = type,
            this._fundDouble = fundDouble;
    }

    get otherFeeType() {
        return this._otherFeeType;
    }

    get fundDouble() {
        return this._fundDouble;
    }

    // valude CsDboule
    set fundDouble(value) {
        this._fundDouble = value;
    }

    add(value) {
        this._fundDouble = this._fundDouble.add(value);
    }

    sub(value) {
        this._fundDouble = this._fundDouble.sub(value);
    }

    // 克隆方法
    static clone(unit) {
        return new OtherFundDouble(OtherFeeType.clone(unit._otherFeeType), new CsFundDouble(unit._fundDouble.value));
    }


    static fromJson(json) {
        return new OtherFundDouble(
            new OtherFeeType(Util.jsonToString(json.id), Util.jsonToString(json.name)),
            Util.jsonToCsFundDouble(json.value)
        );
    }

    toJson() {
        return {
            id: this._otherFeeType.id,
            name: this._otherFeeType.name,
            value: this._fundDouble.value
        };
    }


}